package com.hospital.register.cmn.handler;

import com.alibaba.excel.exception.ExcelAnalysisException;
import com.hospital.register.common.result.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * CMN 异常处理器
 *
 * @author 刘逸晖
 */
@ControllerAdvice
public class CmnExceptionHandler {

    /**
     * 日志记录器
     */
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(ExcelAnalysisException.class)
    @ResponseBody
    public Result handleException(ExcelAnalysisException exception) {
        Result result = Result.fail();
        result.setMessage(exception.getMessage());
        this.logger.error(result.getMessage());
        return result;
    }

}
